package com.luo.controller;

import com.alibaba.fastjson.JSON;
import com.luo.model.Result;
import com.luo.service.GoodService;
import com.sun.org.apache.xml.internal.security.Init;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 功能：
 * 作者：Luo。
 * 日期：2024/1/13 16:27
 */
@WebServlet("/deleteGood")
public class DeleteGoodById extends HttpServlet {

    GoodService goodService = new GoodService();
    Result result = new Result();

    @Override
    protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        int i = goodService.deleteGoodById(id);
        result.setCode("" + i);
        result.setMsg("删除成功");
        String jsonString = JSON.toJSONString(result);
        resp.getWriter().write(jsonString);
        resp.getWriter().close();
    }
}
